package com.greenlife.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.greenlife.commom.ResponseException;
import com.greenlife.common.enums.BaseResultCodeEnum;
import com.greenlife.dao.JunkOrderMapper;
import com.greenlife.model.JunkOrder;
import com.greenlife.service.JunkOrderService;

public class JunkOrderServiceImpl implements JunkOrderService {

	@Autowired
	private JunkOrderMapper junkOrderMapper;

	@Override
	public int deleteByPrimaryKey(JunkOrder junkOrder) {
		int value = junkOrderMapper.deleteByPrimaryKey(junkOrder);
		if (value == 1) {
			return 1;
		} else {
			throw new ResponseException(BaseResultCodeEnum.ERR_CODE_40000);
		}
	}

	@Override
	public int insertSelective(JunkOrder JunkOrder) {
		try {
			int value = junkOrderMapper.insertSelective(JunkOrder);
			if (value == 1)
				return value;
			else
				throw new ResponseException(BaseResultCodeEnum.ERR_CODE_30009);
		} catch (Exception e) {
			throw new ResponseException(BaseResultCodeEnum.ERR_CODE_30009);
		}
	}

	@Override
	public JunkOrder selectByPrimaryKey(JunkOrder JunkOrder) {
		JunkOrder value = junkOrderMapper.selectByPrimaryKey(JunkOrder);
		if (value == null) {
			throw new ResponseException(BaseResultCodeEnum.ERR_CODE_40000);
		}
		return value;
	}

	@Override
	public int updateByPrimaryKeySelective(JunkOrder JunkOrder) {
		int value = junkOrderMapper.updateByPrimaryKeySelective(JunkOrder);
		if (value == 1) {
			return value;
		} else {
			throw new ResponseException(BaseResultCodeEnum.ERR_CODE_10001);
		}
	}

	@Override
	public List<JunkOrder> selectByUserId(JunkOrder JunkOrder) {
		return junkOrderMapper.selectByUserId(JunkOrder);
	}

}